<template>
  <el-dialog :title="!dataForm.id ? '新建' :'编辑'"
             :close-on-click-modal="false" append-to-body
             :visible.sync="visible" class="JNPF-dialog JNPF-dialog_center" lock-scroll
             width="1300px">
    <el-row :gutter="15" class="">
      <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="100px" label-position="right">
        <template v-if="!loading">
          <el-col :span="24">
            <el-card class="mb-20" shadow="always" header="资产信息">
              <el-col :span="6">
                <el-form-item label="资产编号"
                              prop="zcNumber">
                  <el-input v-model="dataForm.zcNumber"
                            placeholder="请输入" clearable :style='{"width":"100%"}'>

                  </el-input>
                </el-form-item>
              </el-col>
            </el-card>
          </el-col>
          <el-col :span="24">
            <el-card class="mb-20" shadow="always" header="经营规划信息">
              <el-col :span="6">
                <el-form-item label="运营公司"
                              prop="jnpf_zcgl_jygh_jnpf_operatingCompany">
                  <el-select v-model=" dataForm.jnpf_zcgl_jygh_jnpf_operatingCompany"
                             placeholder="请选择" clearable :style='{"width":"100%"}'>
                    <el-option v-for="(item, index) in jnpf_zcgl_jygh_jnpf_operatingCompanyOptions" :key="index"
                               :label="item.fullName" :value="item.id" :disabled="item.disabled"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="项目"
                              prop="jnpf_zcgl_jygh_jnpf_project">
                  <el-select v-model=" dataForm.jnpf_zcgl_jygh_jnpf_project"
                             placeholder="请选择" clearable :style='{"width":"100%"}'>
                    <el-option v-for="(item, index) in jnpf_zcgl_jygh_jnpf_projectOptions" :key="index"
                               :label="item.fullName" :value="item.id" :disabled="item.disabled"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="经营方式"
                              prop="jnpf_zcgl_jygh_jnpf_modeOperation">
                  <el-select v-model=" dataForm.jnpf_zcgl_jygh_jnpf_modeOperation"
                             placeholder="请选择" clearable :style='{"width":"100%"}'>
                    <el-option v-for="(item, index) in jnpf_zcgl_jygh_jnpf_modeOperationOptions" :key="index"
                               :label="item.fullName" :value="item.id" :disabled="item.disabled"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="6">
                <el-form-item label="业务状态"
                              prop="jnpf_zcgl_jygh_jnpf_businessStatus">
                  <el-select v-model=" dataForm.jnpf_zcgl_jygh_jnpf_businessStatus"
                             placeholder="请选择" clearable :style='{"width":"100%"}'>
                    <el-option v-for="(item, index) in jnpf_zcgl_jygh_jnpf_businessStatusOptions" :key="index"
                               :label="item.fullName" :value="item.id" :disabled="item.disabled"></el-option>
                  </el-select>
                </el-form-item>
              </el-col>
              <el-col :span="18">
                <el-form-item label="备注"
                              prop="jnpf_zcgl_jygh_jnpf_notes">
                  <el-input v-model=" dataForm.jnpf_zcgl_jygh_jnpf_notes"
                            placeholder="请输入" :style='{"width":"100%"}' true type="textarea"
                            :autosize='{"minRows":4,"maxRows":4}'>
                  </el-input>
                </el-form-item>
              </el-col>
            </el-card>
          </el-col>
        </template>
      </el-form>
      <SelectDialog v-if="selectDialogVisible" :config="currTableConf" :formData="dataForm"
                    ref="selectDialog" @select="addForSelect" @close="selectDialogVisible=false"/>
    </el-row>
    <span slot="footer" class="dialog-footer">
        <el-button @click="visible = false"> 取 消</el-button>
        <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading"> 确 定</el-button>
    </span>
  </el-dialog>
</template>
<script>
import request from '@/utils/request'
import {getDataInterfaceRes} from '@/api/systemData/dataInterface'
import {getDictionaryDataSelector} from '@/api/systemData/dictionary'

export default {
  components: {},
  props: [],
  data() {
    return {
      visible: false,
      loading: false,
      btnLoading: false,
      selectDialogVisible: false,
      currTableConf: {},
      addTableConf: {},
      tableRows: {},
      currVmodel: "",
      dataForm: {
        zcNumber: '',
        zcgl_jygh:
          {
            operatingCompany: '',
            project: '',
            modeOperation: '',
            businessStatus: '',
            notes: '',
          },
        jnpf_zcgl_jygh_jnpf_operatingCompany: "",
        jnpf_zcgl_jygh_jnpf_project: "",
        jnpf_zcgl_jygh_jnpf_modeOperation: "",
        jnpf_zcgl_jygh_jnpf_businessStatus: "",
        jnpf_zcgl_jygh_jnpf_notes: '',
      },
      rules:
        {


          jnpf_zcgl_jygh_jnpf_operatingCompany: [
            {
              required: true,
              message: '请选择',
              trigger: 'change'
            },
          ],
          jnpf_zcgl_jygh_jnpf_project: [
            {
              required: true,
              message: '请选择',
              trigger: 'change'
            },
          ],
          jnpf_zcgl_jygh_jnpf_modeOperation: [
            {
              required: true,
              message: '请选择',
              trigger: 'change'
            },
          ],
          jnpf_zcgl_jygh_jnpf_businessStatus: [
            {
              required: true,
              message: '请选择',
              trigger: 'change'
            },
          ],

        },

      jnpf_zcgl_jygh_jnpf_operatingCompanyOptions: [{"fullName": "运营公司一", "id": "1"}, {"fullName": "运营公司二", "id": "2"}],
      jnpf_zcgl_jygh_jnpf_projectOptions: [{"fullName": "项目一", "id": "1"}, {"fullName": "项目二", "id": "2"}],
      jnpf_zcgl_jygh_jnpf_modeOperationOptions: [],
      jnpf_zcgl_jygh_jnpf_businessStatusOptions: [{"fullName": "业务状态一", "id": "1"}, {"fullName": "业务状态二", "id": "2"}],
    }
  },
  computed: {},
  watch: {},
  created() {
    this.getjnpf_zcgl_jygh_jnpf_modeOperationOptions();
  },
  mounted() {
  },
  methods: {
    getjnpf_zcgl_jygh_jnpf_modeOperationOptions() {
      getDictionaryDataSelector('600000000000000000').then(res => {
        this.jnpf_zcgl_jygh_jnpf_modeOperationOptions = res.data.list
      })
    },
    clearData() {
      this.dataForm.zcNumber = '';
      this.dataForm.zcgl_jygh.operatingCompany = '';
      this.dataForm.zcgl_jygh.project = '';
      this.dataForm.zcgl_jygh.modeOperation = '';
      this.dataForm.zcgl_jygh.businessStatus = '';
      this.dataForm.zcgl_jygh.notes = '';
      this.dataForm.jnpf_zcgl_jygh_jnpf_operatingCompany = "";
      this.dataForm.jnpf_zcgl_jygh_jnpf_project = "";
      this.dataForm.jnpf_zcgl_jygh_jnpf_modeOperation = "";
      this.dataForm.jnpf_zcgl_jygh_jnpf_businessStatus = "";
      this.dataForm.jnpf_zcgl_jygh_jnpf_notes = '';
    },
    init(id) {
      this.dataForm.id = id || 0;
      this.visible = true;
      this.$nextTick(() => {
        this.$refs['elForm'].resetFields();
        if (this.dataForm.id) {
          this.loading = true
          request({
            url: '/api/example/ZcglZcdjInfoTz/' + this.dataForm.id,
            method: 'get'
          }).then(res => {
            this.dataInfo(res.data)
            this.loading = false
          });
        } else {
          this.clearData()
        }
      });
      this.$store.commit('generator/UPDATE_RELATION_DATA', {})
    },
    // 表单提交
    dataFormSubmit() {
      this.$refs['elForm'].validate((valid) => {
        if (valid) {
          this.request()
        }
      })
    },
    request() {
      this.btnLoading = true
      let _data = this.dataList()
      if (!this.dataForm.id) {
        request({
          url: '/api/example/ZcglZcdjInfoTz',
          method: 'post',
          data: _data
        }).then((res) => {
          this.$message({
            message: res.msg,
            type: 'success',
            duration: 1000,
            onClose: () => {
              this.visible = false
              this.btnLoading = false
              this.$emit('refresh', true)
            }
          })
        }).catch(() => {
          this.btnLoading = false
        })
      } else {
        request({
          url: '/api/example/ZcglZcdjInfoTz/' + this.dataForm.id,
          method: 'PUT',
          data: _data
        }).then((res) => {
          this.$message({
            message: res.msg,
            type: 'success',
            duration: 1000,
            onClose: () => {
              this.visible = false
              this.btnLoading = false
              this.$emit('refresh', true)
            }
          })
        }).catch(() => {
          this.btnLoading = false
        })
      }
    },
    openSelectDialog(key) {
      this.currTableConf = this.addTableConf[key]
      this.currVmodel = key
      this.selectDialogVisible = true
      this.$nextTick(() => {
        this.$refs.selectDialog.init()
      })
    },
    addForSelect(data) {
      for (let i = 0; i < data.length; i++) {
        let item = {...this.tableRows[this.currVmodel], ...data[i]}
        this.dataForm[this.currVmodel].push(item)
      }
    },
    dataList() {
      var _data = JSON.parse(JSON.stringify(this.dataForm));
      _data.zcgl_jygh.operatingCompany = _data.jnpf_zcgl_jygh_jnpf_operatingCompany
      _data.zcgl_jygh.project = _data.jnpf_zcgl_jygh_jnpf_project
      _data.zcgl_jygh.modeOperation = _data.jnpf_zcgl_jygh_jnpf_modeOperation
      _data.zcgl_jygh.businessStatus = _data.jnpf_zcgl_jygh_jnpf_businessStatus
      _data.zcgl_jygh.notes = _data.jnpf_zcgl_jygh_jnpf_notes
      return _data;
    },
    dataInfo(dataAll) {
      let _dataAll = dataAll
      _dataAll.jnpf_zcgl_jygh_jnpf_operatingCompany = _dataAll.zcgl_jygh.operatingCompany
      _dataAll.jnpf_zcgl_jygh_jnpf_project = _dataAll.zcgl_jygh.project
      _dataAll.jnpf_zcgl_jygh_jnpf_modeOperation = _dataAll.zcgl_jygh.modeOperation
      _dataAll.jnpf_zcgl_jygh_jnpf_businessStatus = _dataAll.zcgl_jygh.businessStatus
      _dataAll.jnpf_zcgl_jygh_jnpf_notes = _dataAll.zcgl_jygh.notes
      this.dataForm = _dataAll
    },
  },
}

</script>
